package com.ncr.travel.appmgr.client;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.ncr.travel.appmgr.client.gin.Injector;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ApplicationManager implements EntryPoint {

	Logger LOGGER = Logger.getLogger(ApplicationManager.class.getName());

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		setUncaughtExceptionHandler();
		createMain();
	}

	private void createMain() {
		final Injector ginjector = GWT.create(Injector.class);
		AppController appViewer = ginjector.getAppController();
		appViewer.loadApplicationConfiguration();
		RootLayoutPanel rpl = RootLayoutPanel.get();
		ScrollPanel sp = new ScrollPanel();
		rpl.add(sp);
		appViewer.go(sp);
	}

	private void setUncaughtExceptionHandler() {

		GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

			@Override
			public void onUncaughtException(Throwable e) {
				e.printStackTrace();
				LOGGER.log(Level.SEVERE, e.getMessage(), e);
			}
		});
	}
}
